package handler

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	"strconv"
	"time"
	"video-proj/inits"
	"video-proj/internal/dto"
	"video-proj/internal/model"
	"video-proj/response"
)

func ShowUser(c *gin.Context) {

	var user model.User
	err := c.ShouldBind(&user)
	if err != nil {
		response.Error(c, "解析失败")
		return
	}
	err = dto.ShowUser(&user, int(user.ID))
	if err != nil {
		response.Error(c, "查询失败")
		return
	} else {
		response.Success(c, "查询成功", user)
		keyUser := "user" + strconv.Itoa(int(user.ID))
		marshal, err := json.Marshal(&user)
		if err != nil {
			response.Error(c, "解析失败")
			return
		}
		inits.Rdb.Set(inits.Ctx, keyUser, marshal, time.Minute*10)
	}
}
